package top.lyc829.leetcode.T4;

import java.util.ArrayList;
import java.util.List;

class Solution {
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        List<Integer> mix = new ArrayList<>();
        if (nums1.length == 0 && nums2.length == 0) {
            return 0;
        }
        int i = 0, j = 0;
        while (i < nums1.length && j < nums2.length) {
            if (nums1[i] < nums2[j]) {
                mix.add(nums1[i]);
                i++;
            } else {
                mix.add(nums2[j]);
                j++;
            }
        }
        for (int tmp = i; tmp < nums1.length; tmp++) {
            mix.add(nums1[tmp]);
        }
        for (int tmp = j; tmp < nums2.length; tmp++) {
            mix.add(nums2[tmp]);
        }
        if (mix.size() % 2 != 0) {
            return (float) mix.get(mix.size() / 2);
        } else {
            return (double) (mix.get(mix.size() / 2) + mix.get(mix.size() / 2 - 1)) / 2;
        }
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        double res = s.findMedianSortedArrays(new int[]{}, new int[]{});

        System.out.println(res);


    }
}
